import { _decorator, Component, EventTouch, Node, Sprite, tween } from 'cc';
import { back } from './back';
const { ccclass, property } = _decorator;

@ccclass('j5')
export class j5 extends back {
    @property(Node) 
    item1: Node;
    @property(Node) 
    item2: Node;

    start() {
        this.item2.on(Node.EventType.TOUCH_START,this.handleRedBtnTouchStart,this);
        this.item2.on(Node.EventType.TOUCH_MOVE, (event: EventTouch) => {}, this);
        this.item2.on(Node.EventType.TOUCH_END, this.handleRedBtnTouchEnd, this);
        this.item2.on(Node.EventType.TOUCH_CANCEL, this.handleRedBtnTouchEnd, this);//当手指在目标节点区域外离开屏幕时
    }

    update(deltaTime: number) {
        
    }
    handleRedBtnTouchStart(event:EventTouch){
        tween(this.item2).to(0.1, { angle: 180 }).start();
        const spriteComp = this.item1.getComponent(Sprite);
        spriteComp.grayscale = true;
    }
    handleRedBtnTouchEnd(){
        tween(this.item2).to(0.1, { angle: 0 }).start();
        const spriteComp = this.item1.getComponent(Sprite);
        spriteComp.grayscale = false;
    }
}


